package vcp.gui.forms;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;

import vcp.common.IView;
import vcp.gui.components.VCPPanel;

import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.sql.Timestamp;
import java.util.Observable;
import java.util.Observer;

import com.toedter.calendar.JDateChooser;



public class OrderOccasionalForm extends VCPPanel implements Observer,IView {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField textCID;
	private JLabel lblNewOrderError;

 	
	/* validators */
	private boolean isValidForm=false;
	private JTextField carNo_field;
	private JTextField hTime_field;
	private JTextField email_field;
	private JLabel lblLeaveDate;
	JDateChooser dateChooser;
	private JLabel label;
	private JTextField mTime_field;
	
	private JButton btnSend;

	public OrderOccasionalForm() {
		setBackground(Color.WHITE);
		  buildForm();
	}
	
	private void buildForm(){

		textCID = new JTextField();
		textCID.setColumns(10);

		JLabel lblCID = new JLabel("Customer ID");

		btnSend = new JButton("create");


		lblNewOrderError = new JLabel("");
		lblNewOrderError.setForeground(Color.RED);
		
		carNo_field = new JTextField();
		carNo_field.setColumns(10);
		
		hTime_field = new JTextField();
		hTime_field.setColumns(10);
		
		email_field = new JTextField();
		email_field.setColumns(10);
		
		JLabel lblCarNumber = new JLabel("Car Number");
		
		JLabel lblLeaveTime = new JLabel("Leave Time");
		
		JLabel lblEmail = new JLabel("E-Mail");
		
		lblLeaveDate = new JLabel("Leave Date");
		
		dateChooser = new JDateChooser();
		
		label = new JLabel(":");
		
		mTime_field = new JTextField();
		mTime_field.setColumns(10);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblCID)
							.addContainerGap(350, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblCarNumber, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
							.addContainerGap(342, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblLeaveTime, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
										.addComponent(textCID, Alignment.TRAILING)
										.addComponent(carNo_field, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(hTime_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(label)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(mTime_field, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE))))
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
									.addGroup(groupLayout.createSequentialGroup()
										.addComponent(lblEmail, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(ComponentPlacement.RELATED)
										.addComponent(email_field, GroupLayout.PREFERRED_SIZE, 321, GroupLayout.PREFERRED_SIZE))
									.addComponent(lblNewOrderError)
									.addGroup(groupLayout.createSequentialGroup()
										.addPreferredGap(ComponentPlacement.RELATED, 208, Short.MAX_VALUE)
										.addComponent(lblLeaveDate, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
										.addGap(18)
										.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
									.addComponent(btnSend, Alignment.TRAILING)))
							.addGap(16))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(lblNewOrderError)
					.addGap(24)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCID)
						.addComponent(textCID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCarNumber)
						.addComponent(carNo_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblLeaveTime)
							.addComponent(hTime_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(label)
							.addComponent(mTime_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(lblLeaveDate))
						.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblEmail)
						.addComponent(email_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addComponent(btnSend)
					.addContainerGap(40, Short.MAX_VALUE))
		);
		setLayout(groupLayout);

	}

	@Override
	public void addController(Object obj) {
		btnSend.addActionListener((ActionListener)obj);
		btnSend.setActionCommand("orderOccasional");
	}

	@Override
	public void update(Observable o, Object arg) {
		//if(arg.toString().equals("createOccasionalOK"))
		   System.out.println(arg);	
	}

	public JTextField getTextCID() {
		return textCID;
	}

	public void setTextCID(JTextField textCID) {
		this.textCID = textCID;
	}

	public JLabel getLblNewOrderError() {
		return lblNewOrderError;
	}

	public void setLblNewOrderError(JLabel lblNewOrderError) {
		this.lblNewOrderError = lblNewOrderError;
	}

	public boolean isValidForm() {
		return isValidForm;
	}

	public void setValidForm(boolean isValidForm) {
		this.isValidForm = isValidForm;
	}

	public JTextField getCarNo_field() {
		return carNo_field;
	}

	public void setCarNo_field(JTextField carNo_field) {
		this.carNo_field = carNo_field;
	}

	public JTextField gethTime_field() {
		return hTime_field;
	}

	public void sethTime_field(JTextField hTime_field) {
		this.hTime_field = hTime_field;
	}

	public JTextField getEmail_field() {
		return email_field;
	}

	public void setEmail_field(JTextField email_field) {
		this.email_field = email_field;
	}

	public JLabel getLblLeaveDate() {
		return lblLeaveDate;
	}

	public void setLblLeaveDate(JLabel lblLeaveDate) {
		this.lblLeaveDate = lblLeaveDate;
	}

	public JDateChooser getDateChooser() {
		return dateChooser;
	}

	public void setDateChooser(JDateChooser dateChooser) {
		this.dateChooser = dateChooser;
	}

	public JLabel getLabel() {
		return label;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}

	public JTextField getmTime_field() {
		return mTime_field;
	}

	public void setmTime_field(JTextField mTime_field) {
		this.mTime_field = mTime_field;
	}

	public JButton getBtnSend() {
		return btnSend;
	}

	public void setBtnSend(JButton btnSend) {
		this.btnSend = btnSend;
	}

}


